import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import os
import warnings
warnings.filterwarnings('ignore')
pd.set_option('max_colwidth',200)
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
pd.set_option('display.width', 1000)

root_path = os.path.abspath('../../')

font1 = {
    'family' : 'Times New Roman',
'weight' : 'normal',
'size'   : 16,
}

fontlegend = {
    'family' : 'Times New Roman',
'weight' : 'normal',
'size'   : 14,
}

data_path = root_path + "/asset/mergingData100m.csv"
ori_data = pd.read_csv(data_path)

mergingData = ori_data[
    (ori_data['MergingState'] == True)
    & (ori_data['RouteClass'] == 'entry')
    & (ori_data['BreakRuleState'] == 'None')
    & (ori_data['MergingDistance'] != 'None')
    & (ori_data['MaxLateralSpeed'] != 'None')
    & (ori_data['MergingType'] != 'None')
    ]
mergingData['MergingDistance'] = mergingData['MergingDistance'].astype('float')
mergingData['MergingDuration'] = mergingData['MergingDuration'].astype('float')
mergingData['MaxLateralSpeed'] = mergingData['MaxLateralSpeed'].astype('float')
mergingData['MaxiLateralAcc'] = mergingData['MaxiLateralAcc'].astype('float')
mergingData['MergingDistanceRatio'] = mergingData['MergingDistanceRatio'].astype('float')

mergingData.sort_values(by="vehicleClass", inplace=True)

FONTSIZE = 16
plt.figure(figsize=(20, 12))
plt.style.use('seaborn-colorblind')
ax1 = plt.subplot(2,2,1)
g1 = sns.boxplot(x="MergingType", y="MergingDistanceRatio",data=mergingData,hue = "vehicleClass",showmeans=True,whis = 3,
            order=["A", "B", "C","D", "E", "F"], meanprops = {'marker':'D','markerfacecolor':'red'},palette="hls",saturation=0.6, showfliers = True)
plt.xticks(fontsize=FONTSIZE)
plt.yticks(fontsize=FONTSIZE)
g1.set(xlabel=None)
plt.grid(ls='-',axis="both")
plt.title("MergingDistanceRatio")
sns.set_context("notebook")
plt.legend(prop=fontlegend)

ax2 = plt.subplot(2,2,2)
g1 = sns.boxplot(x="MergingType", y="MergingDuration",data=mergingData,hue = "vehicleClass",showmeans=True,whis = 3,
            order=["A", "B", "C","D", "E", "F"], meanprops = {'marker':'D','markerfacecolor':'red'},palette="hls",saturation=0.6, showfliers = True)
plt.xticks(fontsize=FONTSIZE)
plt.yticks(fontsize=FONTSIZE)
g1.set(xlabel=None)
plt.grid(ls='-',axis="both")
plt.title("MergingDuration")
sns.set_context("notebook")
plt.legend(prop=fontlegend)

ax3 = plt.subplot(2,2,3)
g1 = sns.boxplot(x="MergingType", y="MaxLateralSpeed",data=mergingData,hue = "vehicleClass",showmeans=True,whis = 3,
            order=["A", "B", "C","D", "E", "F"], meanprops = {'marker':'D','markerfacecolor':'red'},palette="hls",saturation=0.6, showfliers = True)
plt.xticks(fontsize=FONTSIZE)
plt.yticks(fontsize=FONTSIZE)
g1.set(xlabel=None)
plt.grid(ls='-',axis="both")
plt.title("MaxLateralSpeed")
sns.set_context("notebook")
plt.legend(prop=fontlegend)

ax4 = plt.subplot(2,2,4)
g1 = sns.boxplot(x="MergingType", y="MaxiLateralAcc",data=mergingData,hue = "vehicleClass",showmeans=True,whis = 3,
            order=["A", "B", "C","D", "E", "F"], meanprops = {'marker':'D','markerfacecolor':'red'},palette="hls",saturation=0.6, showfliers = True)
plt.xticks(fontsize=FONTSIZE)
plt.yticks(fontsize=FONTSIZE)
g1.set(xlabel=None)
plt.grid(ls='-',axis="both")
plt.title("MaxiLateralAcc")
sns.set_context("notebook")
plt.legend(prop=fontlegend)

plt.tight_layout()
plt.show()
